package com.xys.auth.service.impl;

import com.xys.auth.bean.Permission;
import com.xys.auth.mapper.PermissionMapper;
import com.xys.auth.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
public class PermissionService implements IPermissionService {

    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public List<Permission> findAll() {
        return permissionMapper.findAll();
    }

    @Override
    public int save(Permission permission) {
        permission.setId(UUID.randomUUID().toString().replace("-",""));
        return permissionMapper.insert(permission);
    }

    @Override
    public List<Permission> findOtherPermission(String id) {
        return permissionMapper.findOtherPermission(id);
    }

    @Override
    public Permission findById(String id) {
        return permissionMapper.findById(id);
    }

    @Override
    @Transactional
    public int deletePermission(String id) {
        permissionMapper.deleteFromRolePermission(id);
        return permissionMapper.deleteById(id);
    }
}
